import { Component } from '@angular/core';
import {IonicPage , NavParams} from 'ionic-angular';
import {Util} from "@providers/util";

@IonicPage()
@Component({
  selector: 'like-query',
  templateUrl: 'like-query.html',
})

export class LikeQueryPage {

  datas: any[] = [];
  query_field: any;
  datasLikeQuery: any[] = [];
  constructor(private navParams: NavParams) {
    this.datas = this.navParams.get("datas");
  }

  /**
   * Enter查询输入
   */
  inputs(event) {
    if(event.keyCode == 13) {
      this.query();
    }
  }

  /**
   * 失去焦点查询
   */
  loseFocus() {
    this.query();
  }

  /**
   * 查询
   */
  query() {
    if(Util.isNull(this.query_field)) {
      return;
    }
    this.datasLikeQuery = [];
    this.datas.forEach( data => {
      let field = this.query_field + "";
      let name = data.PRODUCT_NAME + "";
      let num = data.PRODUCT_ID + "";
      if(name.includes(field ,0) || num.includes(field , 0)){
        this.datasLikeQuery.push(data);
      }
    });
  }

}
